/*
 * AGENT SHERPA
 *  
 * Assignement 2 of the Agent Oriented Software Engineering Course
 * M.Sc. in Advanced Software Engineering (Part-time)
 * University College Dublin www.ucd.ie
 *
 * Copyright (c) 2007 Chris Walsh, Aidan Morrisy and Iain Hull.
 * All rights reserved.
 */

package org.agentsherpa;

import org.agentsherpa.model.GlobalMap;
import com.agentfactory.platform.interfaces.Module;
    
import org.agentsherpa.model.Point;
import org.agentsherpa.SimulatorService;
/**
 * LocationModule stores the agents location and map state. Interfaces with the
 * SimulatorService to update the current map.
 */
public class LocationModule_1 extends Module {
    
    private Point[] road;
    private SimulatorService simulator;
    
    public void init() {
        
      
     //SimulatorService simulator = (SimulatorService) getService("org.agentsherpa.SimulatorService");
            // TODO move to module
            // currently returns full map
            
        GlobalMap map = simulator.getMap();
        int roadArray = 0;
	for(int x = 0; x < map.getWidth(); ++x) {
                for(int y = 0; y < map.getHeight(); ++y) {
                    Point p = new Point(x, y);
                    if (map.isRoad(p)) {
                        System.out.print("*");
                       // adoptBelief("BELIEF(road" + p + ")");  
                        road[roadArray] = p;
                        roadArray++;
                        
                    }
                    else {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }



    public void destroy() {
    }
    public boolean isRoad (Point location){
        
        for (int i = 0; i < road.length; i++){
            //System.out.println("LocationModule: Array Loop  " + i);
            //System.out.println("LocationModule: Array Point = " + road[i]);
            //System.out.println("LocationModule: South Point = " + location);
                    if (road[i].getX() == location.getX()){
                            if (road[i].getY() == location.getY()){
                                     return true;
                                } 
                    }
        
	}
       return false;
    }

   
    
    
    private Point[] road(){
    
    Point[] road;
    road = new Point[16];
    road[0] = new Point(1,1);
    road[1] = new Point(1,2);
    road[2] = new Point(1,3);
    road[3] = new Point(1,4);
    road[4] = new Point(2,1);
    road[5] = new Point(2,2);
    road[6] = new Point(2,3);
    road[7] = new Point(2,4);
    road[8] = new Point(3,1);
    road[9] = new Point(3,2);
    road[10] = new Point(3,3);
    road[11] = new Point(3,4);
    road[12] = new Point(4,1);
    road[13] = new Point(4,2);
    road[14] = new Point(4,3);
    road[15] = new Point(4,4);
    
    return road;
    }
    

}


